//
//  WPNewTreamentInstructionNoImagesCell.m
//  wobingwoyi
//
//  Created by WGP on 2016/12/5.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPNewTreamentInstructionNoImagesCell.h"

@interface WPNewTreamentInstructionNoImagesCell ()

@property(nonatomic,strong)UIView *topView;
@property(nonatomic,strong)UIImageView *lineImageView;
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UILabel *specificTimeLabel;
@property(nonatomic,strong)UILabel *descriptionLabel;

@end
@implementation WPNewTreamentInstructionNoImagesCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        UIImageView *lineImageView = [UIImageView lineImageView];
        [self.contentView addSubview:lineImageView];
        
        [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
        
        [self topView];
        [self lineImageView];
        [self descriptionLabel];
    }
    return self;
}

-(UIView *)topView
{
    if (_topView == nil)
    {
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_topView];
        
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.height.mas_equalTo(44);
        }];
        
        UIImageView *topLine = [UIImageView lineImageView];
        UIImageView *bottomLine = [UIImageView lineImageView];
        
        [_topView addSubview:topLine];
        [_topView addSubview:bottomLine];
        
        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(_topView);
            make.height.mas_equalTo(0.5);
        }];
        
        [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(_topView);
            make.height.mas_equalTo(0.5);
        }];
        
        _timeLabel = [UILabel new];
        _timeLabel.textColor = GLobalFontColor;
        _timeLabel.text = @"症状时间:";
        _timeLabel.font = [UIFont systemFontOfSize:14];
        [_topView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_topView).offset(20);
            make.centerY.equalTo(_topView);
        }];
        
        _specificTimeLabel = [UILabel new];
        _specificTimeLabel.font = [UIFont systemFontOfSize:14];
        _specificTimeLabel.textColor = GLobalFontColor;
        //        _specificTimeLabel.text = [[WPDateFormatterManager sharedManager] stringFromDateWithDate:[NSDate date] format:@"yyyy-MM-dd"];
        [_topView addSubview:_specificTimeLabel];
        
        [_specificTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_topView);
            make.left.equalTo(_timeLabel.mas_right).offset(8);
        }];
        
        UIButton *addPictureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [addPictureBtn setTitle:@"编辑" forState:UIControlStateNormal];
        addPictureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [addPictureBtn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        [_topView addSubview:addPictureBtn];
        
        [addPictureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_topView);
            make.right.equalTo(_topView).offset(-10);
        }];
        
        UIButton *coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        coverBtn.backgroundColor = [UIColor clearColor];
        [coverBtn addTarget:self action:@selector(addPictureBtnDidClick:) forControlEvents:UIControlEventTouchDown];
        [_topView addSubview:coverBtn];
        
        [coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(_topView);
            make.left.equalTo(_topView.mas_centerX);
        }];
        
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zhenduanBJ"]];
        [_topView addSubview:imageView];
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_topView);
            make.right.equalTo(addPictureBtn.mas_left).offset(-8);
        }];
    }
    return _topView;
}

-(UIImageView *)lineImageView
{
    if (_lineImageView == nil)
    {
        _lineImageView = [[UIImageView alloc] init];
        _lineImageView.backgroundColor = GlobalColor;
        [self.topView addSubview:_lineImageView];
        
        [_lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topView).offset(10);
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(24);
            make.centerY.equalTo(self.topView);
        }];
    }
    return _lineImageView;
}

-(UILabel *)descriptionLabel
{
    if (_descriptionLabel == nil)
    {
        _descriptionLabel = [UILabel new];
        _descriptionLabel.textColor = GLobalFontColor;
        _descriptionLabel.font = [UIFont systemFontOfSize:15];
        _descriptionLabel.numberOfLines = 2;
        
        [self.contentView addSubview:_descriptionLabel];
        
        [_descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topView.mas_bottom).offset(15);
            make.left.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView).offset(-10);
            make.bottom.equalTo(self.contentView).offset(-15);
        }];
    }
    return _descriptionLabel;
}

-(void)addPictureBtnDidClick:(UIButton *)btn
{
    if (self.editeBtnBlock)
    {
        self.editeBtnBlock();
    }
}

-(void)setDescpStr:(NSString *)descpStr
{
    _descpStr = descpStr;
    
    if(self.descpTime.length)
    {
        self.specificTimeLabel.text = self.descpTime;
    }
    else
    {
        self.specificTimeLabel.text = @"";
    }
    
    if (self.descpStr.length)
    {
        self.descriptionLabel.text = self.descpStr;
        self.descriptionLabel.textColor = RGB_SAME(51);
    }
    else
    {
        self.descriptionLabel.text = @"暂无症状描述";
        self.descriptionLabel.textColor = RGB_SAME(153);
    }
}

-(void)setIsVisit:(BOOL)isVisit
{
    _isVisit = isVisit;
    
    if (isVisit)
    {
        self.lineImageView.hidden = NO;
        [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_topView).offset(20);
        }];
    }
    else
    {
        self.lineImageView.hidden = YES;
        [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_topView).offset(10);
        }];
    }
}

@end
